<?php
/**
 * Created by PhpStorm.
 * User: hoter.zhang
 * Date: 2018/1/3
 * Time: 16:31
 */

namespace app\services;


use Yii;

class StaticService{

    /**
     * @param $type
     * @param $path
     * @param $depend
     * 統一加載JS CSS
     */
    public static function includeAppStatic($type, $path, $depends) {
        //加入版本號
        $release_version = define("RELEASE_VERSION") ? RELEASE_VERSION : "20190103141600";
        if (stripos($path, "?") !== false) {
            $path = $path . "&version={$release_version}";
        } else {
            $path = $path . "?version={$release_version}";
        }

        if ($type == "css") {
            Yii::$app->getView()->registerCssFile($path, ['depends' => $depends]);
        } else {
            Yii::$app->getView()->registerJsFile($path, ['depends' => $depends]);
        }
    }

    //加載JS
    public static function includeAppJsStatic($path, $depends) {
        self::includeAppStatic("js", $path, $depends);
    }

    //加載CSS
    public static function includeAppCssStatic($path, $depends) {
        self::includeAppStatic("css", $path, $depends);
    }
}